package com.kaigejava.springcloud.controller;


import com.kaigejava.springcloud.entities.CommonResult;
import com.kaigejava.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author kaigejava
 * odercontroller-重构之前的
 */
@RestController
@Slf4j
@RequestMapping("/consumer/")
public class OrderController {

    public static final String PAYMENT_URL = "http://localhost:8080/payment";

    @Autowired
    private RestTemplate restTemplate;


    /**
     * 创建支付
     *
     * @param payment
     * @return
     */
    @GetMapping("payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment) {

        return restTemplate.postForObject(PAYMENT_URL + "/create", payment, CommonResult.class);
    }

    /**
     * 根据id查询支付信息
     *
     * @param id
     * @return
     */
    @GetMapping("payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        log.info("==进入了get:{}", id);
        String url = PAYMENT_URL + "/get/" + id;
        log.info("==访问的url；" + url);

        return restTemplate.getForObject(url, CommonResult.class);
    }
}
